#include "vtor_heap.h"

#ifdef __VTOR_HEAP__

void* VtorHeap_Buf0[0x400 + 12 * 2] = { 0 };
void* VtorHeap_BufArray[3] = { 0 };



int VtorHeap_Test0(void)
{
	int* heap[10] = { 0 };

	VtorHeap_Init(VtorHeap_Buf0, 0x400 + 12 * 2);
	VtorHeapDebug("after init\r\n");
	VtorHeap_PrintInfo(0);


	heap[0] = (int*)VtorHeap0_Malloc(0x100 - 12);
	heap[1] = (int*)VtorHeap0_Malloc(0x100 - 12);
	heap[2] = (int*)VtorHeap0_Malloc(1);
	heap[3] = (int*)VtorHeap0_Malloc(0x100 - 12);
	heap[4] = (int*)VtorHeap0_Malloc(2);
	VtorHeapDebug("after malloc\r\n");
	VtorHeap_PrintInfo(0);

	VtorHeap_Free(heap[0]);
	VtorHeap_Free(heap[1]);
	VtorHeapDebug("after free\r\n");
	VtorHeap_PrintInfo(0);
	VtorHeap_Free(heap[0]);
	VtorHeapDebug("after refree\r\n");
	VtorHeap_PrintInfo(0);
	
	
	VtorHeap_Free(heap[2]);
	VtorHeap_Free(heap[3]);
	VtorHeap_Free(heap[4]);
	VtorHeapDebug("after all free\r\n");
	VtorHeap_PrintInfo(0);
	return 0;
}


VtorHeapNode* VtorHeap_GetHeadNode(int heapIdx)
{
	return (VtorHeapNode*)VtorHeap_BufArray[heapIdx];
}

void VtorHeap_SetHeadNode(int heapIdx, void* heapBuf)
{
	VtorHeap_BufArray[heapIdx] = heapBuf;
}

#endif // __VTOR_HEAP__


